Skip to content

Conversation

@docto-rin
Copy link
Owner

result = 1
bit = 1
power = x
abs_n = abs(n)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absで回さずに、if n < 0: return 1 / myPow(x, -n)を最初の方に持ってきてここにくる段階ではn > 0の時を考えれば良いようにした方が見やすくなる気がしました。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。

確かにそうですね。その手があったんですね。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

関数を一段階深くするのもいいんですが、ちょっと重い(といっても数ナノ秒、どちらかというとスタックが深くなるのでデバッグが面倒になるほうが気にしているかもな)ので条件分岐で済むならそちらも一つでしょう。


result = 1
bit = 1
power = x
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xを何乗かしたものであるというのを明らかにしておくために、x_poweredみたいな名前にしてもいいと思いました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants